<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>系统界面 OutlookTree</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link href="/resources/js/miniui/themes/default/miniui.css"
	rel="stylesheet" type="text/css" />

<style type="text/css">
body {
	margin: 0;
	padding: 0;
	border: 0;
	width: 100%;
	height: 100%;
	overflow: hidden;
}

.header {
	background: url(/resources/img/header.gif) repeat-x 0 -1px;
}
</style>
</head>
<body>

	<!--Layout-->
	<div id="layout1" class="mini-layout"
		style="width: 100%; height: 100%;">
		<div class="header" region="north" height="70" showSplit="false"
			showHeader="false">
			<h1
				style="margin: 0; padding: 15px; cursor: default; font-family: 微软雅黑, 黑体, 宋体;">天禾人才后台管理系统</h1>
			<div style="position: absolute; top: 18px; right: 10px;">
				<a class="mini-button mini-button-iconTop userphone"
					iconCls="icon-edit" onclick="onClick" plain="true">欢迎用户: <%=request.getAttribute("userPhone")%></a>
				<a class="mini-button mini-button-iconTop" iconCls="icon-edit"
					onclick="updatePwd()" plain="true">修改密码</a> <a
					class="mini-button mini-button-iconTop" iconCls="icon-close"
					onclick="logout()" plain="true">注销</a>

			</div>

		</div>
		<div title="south" region="south" showSplit="false" showHeader="false"
			height="30">
			<div style="line-height: 28px; text-align: center; cursor: default">Copyright
				© 武汉天禾人才有限公司版权所有</div>
		</div>
		<div region="west" title="在线演示" showHeader="true"
			bodyStyle="padding-left:1px;" showSplitIcon="true" width="230"
			minWidth="100" maxWidth="350">
			<ul id="userMenuTree" class="mini-tree" style="width: 300px;"
				showTreeIcon="true" textField="name" idField="id" expandOnLoad="0"
				allowSelect="true"  onbeforenodeselect="changeView"
				enableHotTrack="true">
			</ul>

		</div>
		<div title="center" region="center" style="border: 0;">
			<div id="mainTabs" class="mini-tabs" activeIndex="0"
				style="width: 100%; height: 100%;"
				onactivechanged="onTabsActiveChanged">
				<div title="首页">
					<iframe id="mainframe" frameborder="0" name="main"
						style="width: 100%; height: 100%;" border="0"></iframe>
				</div>
			</div>
		</div>
	</div>

	<div id="resetPwdwindow" class="mini-window" title="修改登录密码"
		style="width: 350px;" showModal="true" allowResize="true"
		allowDrag="true">
		<div id="resetPwdform" class="form">
			<input class="mini-hidden" name="id" value="0" />
			<table style="width: 100%; text-align: center;">
				<tr>
					<td style="width: 30%; text-align: right;">原密码：</td>
					<td style="width: 40%; text-align: left;"><input name="oldPwd"
						class="mini-password" emptyText="请输入原密码" /></td>
					<td style="width: 30%;" id="oldPwd_error" class="errorText"></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right">新密码：</td>
					<td style="width: 40%; text-align: left;"><input name="newPwd"
						class="mini-password" emptyText="请输入密码" /></td>
					<td style="width: 30%;" id="newPwd_error" class="errorText"></td>
				</tr>
				<tr>
					<td style="width: 30%; text-align: right">再次输入：</td>
					<td style="width: 40%; text-align: left;"><input
						name="reNewPwd" class="mini-password" emptyText="请输入密码" /></td>
					<td style="width: 30%;" id="reNewPwd_error" class="errorText"></td>
				</tr>
				<tr>
					<td
						style="text-align: center; padding-top: 5px; padding-right: 20px;"
						colspan="6"><a class="mini-button"
						img="/resources/js/miniui/themes/icons/save.gif"
						onclick="saveResetPwdRow()">保存</a> <a class="mini-button"
						img="/resources/js/miniui/themes/icons/cancel.gif"
						onclick="cancelRow()">取消</a></td>
				</tr>
			</table>
		</div>
	</div>

<script src="/resources/js/jquery-1.6.2.min.js"
	type="text/javascript"></script>
<script src="/resources/js/core.js"
	type="text/javascript"></script>	
<script src="/resources/js/miniui/miniui.js"
	type="text/javascript"></script>
	<script type="text/javascript">
		mini.parse();
		
		$.ajax({
			url : "/system/selectAllMenu",
			type : "post",
			dataType : "json",
			success : function(list) {
				var menuTree = mini.get("userMenuTree");
				menuTree.loadList(list, "id", "pid");
			},
			error : function(jqXHR, textStatus, errorThrown) {
				alert(jqXHR.responseText);
			}
		});
		
		 //--------------------------------
        function changeView(e) {
        	
            var tree = e.sender;
            var node = e.node;
            console.log(node);
            console.log(node);
            if(node.pid != -1 && node.url != "/" )
           	 $('#mainframe').attr("src",node.url);
        }
		
		function logout(){
			window.location = "/user/logout";
		}
		
		function updatePwd(){
			var resetPwdwindow = mini.get("resetPwdwindow");
			var resetPwdform = new mini.Form("resetPwdform");
			resetPwdwindow.show();
			resetPwdform.clear();
		}
		
		function saveResetPwdRow(){
			var resetPwdform = new mini.Form("resetPwdform");
			var data = resetPwdform.getData();
			console.log(data);
			
			if (data.oldPwd == '' || data.oldPwd.length < 6) {
				$('#oldPwd_error').empty().html("密码格式不对");
				return false;
			} else {
				$('#oldPwd_error').html("");
			}

			if (data.newPwd == '' || data.newPwd.length < 6) {
				$('#newPwd_error').html("密码格式不对");
				return false;
			} else {
				$('#enable_error').html("");
			}

			if (data.reNewPwd == '' || data.newPwd != data.reNewPwd) {
				$('#reNewPwd_error').html("2次输入有误");
				return false;
			} else {
				$('#reNewPwd_error').html("");
			}
			
			data.phone = '<%=request.getAttribute("userPhone")%>';
		
			$.ajax({
				url : "/user/updatePwd",
				data : data,
				type : "post",
				dataType : "json",
				success : function(data) {
					if (data.code == 0) {
						var resetPwdwindow = mini.get("resetPwdwindow");
						resetPwdwindow.hide();
						mini.alert("修改成功");
					} else {
						mini.alert(data.data);
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
					alert(jqXHR.responseText);
				}
			});
		}

		function cancelRow() {
			var resetPwdwindow = mini.get("resetPwdwindow");
			resetPwdwindow.hide();
		}
	</script>
</body>
</html>